package code;
import java.io.IOException;

import global.Convert;
import global.PageId;
import global.RID;
import global.SystemDefs;
import global.GlobalConst;
import global.TID;
import heap.FieldNumberOutOfBoundException;
import heap.HFBufMgrException;
import heap.HFDiskMgrException;
import heap.HFException;
import heap.InvalidSlotNumberException;
import heap.InvalidTupleSizeException;
import heap.InvalidTypeException;
import heap.SpaceNotAvailableException;
import heap.Triple;
import heap.TripleHeapfile;
import heap.Tuple;


public class MyInterface {

	public static void printTriple (Triple t) throws FieldNumberOutOfBoundException, IOException {
		System.out.println(t.getIntFld(1));
		System.out.println(t.getIntFld(2));
		System.out.println(t.getIntFld(3));
		System.out.println(t.getFloFld(4));
	}
	
	public static void printTriple (Tuple t) throws FieldNumberOutOfBoundException, IOException {
		System.out.println(t.getIntFld(1));
		System.out.println(t.getIntFld(2));
		System.out.println(t.getIntFld(3));
		System.out.println(t.getFloFld(4));
	}
	
	public static void main (String [] args) throws InvalidSlotNumberException, InvalidTupleSizeException, HFException, HFDiskMgrException, HFBufMgrException, Exception{
		String dbpath = "/tmp/dbtest";
		int NUMBUF = 100; 
		SystemDefs sysdef = new SystemDefs( dbpath, 1000, NUMBUF, "Clock" );
		Triple t = null;
		t = new Triple ();
		//printTriple(t);
		t.setIntFld(1, 1);
		t.setIntFld(2, 2);
		t.setIntFld(3, 3);
		t.setFloFld(4, (float) .9);
		printTriple(t);
		//t.addTriple(1, 3, 11, (float) 1.4);
		t.printTuple();
		TripleHeapfile hfile = null;
		hfile = new TripleHeapfile("heap1");
		RID rid = new RID (new PageId(1), 1);
		System.out.println(hfile.getRecord(rid));		
		rid = hfile.insertRecord(t.returnTupleByteArray());
		System.out.println(hfile.getRecCnt());	
		Tuple nt = hfile.getRecord(rid);
		t.tupleCopy(nt);
		System.out.println(t);
		printTriple (t);
	}
}
